﻿<TextBox x:Class="SLS.Controls.PopUpMenuTextBox"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:my="clr-namespace:SLS.Controls"
         xmlns:converts="clr-namespace:SLS.ExClassLib.Converters;assembly=Converters"
         Width="Auto"
         Style="{DynamicResource autoCompleteTextBox}"
         >
    <TextBox.Resources>
        <ResourceDictionary>
            <Style x:Key="autoCompleteTextBox"
                   TargetType="{x:Type TextBox}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TextBoxBase}">
                            <Border Name="Border"
                                    CornerRadius="2" 
                                    BorderBrush="Yellow"
                                    BorderThickness="1"
                                    Padding="1">
                                <Grid x:Name="root">
                                    <ScrollViewer Margin="0"
                                                  x:Name="PART_ContentHost" />
                                    <Popup x:Name="PART_Popup"
                                           AllowsTransparency="true"
                                           Placement="Custom"
                                           IsOpen="False"
                                           PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}"
                                           VerticalOffset="{Binding Path=Top, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
                                           HorizontalOffset="{Binding Path=Left, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
                                        <Border x:Name="DropDownBorder"
                                                Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
                                                Width="200"
                                                MinWidth="{Binding Path=ActualWidth, ElementName=root}"
                                                BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
                                                BorderThickness="1">
                                            <Menu VerticalContentAlignment="Stretch"
                                                  HorizontalContentAlignment="Stretch"
                                                  ItemsSource="{Binding}"
                                                ></Menu>
                                                
                                        </Border>
                                    </Popup>
                                </Grid>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </ResourceDictionary>
    </TextBox.Resources>
</TextBox>
